<template>
	<view class="container">
		<view class="detail-container" v-if="note">
			<text class="title">{{ note.title || '无标题' }}</text>
			<text class="date">{{ formatDate(note.updated_at) }}</text>
			<view class="content" style="padding-left: 12rpx;">
				<text>{{ note.content }}</text>
			</view>

			<view class="content-count">
				<span>{{note.content.length}}/1000</span>
			</view>

		</view>

		<view class="empty" v-else>
			<image src="/static/logo.png" class="empty-img" />
			<text class="empty-text">笔记不存在</text>
			<button class="empty-btn" @click="goBack">返回</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				note: null
			};
		},
		onLoad(options) {
			if (options.id) {
				this.getNoteDetail(options.id);
			}
		},
		methods: {
			async getNoteDetail(id) {
				uni.showLoading({
					title: '加载中'
				});
				const res = await uniCloud.callFunction({
					name: 'note',
					data: {
						action: 'getDetail',
						params: {
							id
						}
					}
				});
				uni.hideLoading();

				if (res.result.code === 200) {
					this.note = res.result.data;
				} else {
					uni.showToast({
						title: '加载失败',
						icon: 'none'
					});
				}
			},

			goBack() {
				uni.navigateBack();
			},

			formatDate(timestamp) {
				if (!timestamp) return '';
				const date = new Date(timestamp);
				return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
			}
		}
	};
</script>

<style scoped>
	.container {
		background-color: #FFFDD0;
		/* 米黄色纸张底色 */
		min-height: 100vh;
		/* height: auto; */
		padding: 20rpx;

	}

	.detail-container {
		padding: 30rpx;
		background-color: #FFFDF5;
		/* 比背景稍白的纸张色 */
		border-radius: 12rpx;
		box-shadow: 0 4rpx 12rpx rgba(139, 125, 107, 0.05);
		border: 1rpx solid #E0D5C8;
		/* 纸张边缘线 */
		margin-bottom: 40rpx;
	}

	.title {
		font-size: 44rpx;
		font-weight: bold;
		color: #5C4A36;
		/* 深棕色标题 */
		display: block;
		margin-bottom: 20rpx;
		border-bottom: 1rpx solid #D4C9B8;
		/* 标题下划线 */
		padding-bottom: 20rpx;
	}

	.date {
		font-size: 28rpx;
		color: #8B7D6B;
		/* 复古日期色 */
		display: block;
		margin-bottom: 40rpx;
	}

	.content {
		font-size: 34rpx;
		color: #6E5C4B;
		/* 正文棕色 */
		line-height: 1.8;
		background-color: transparent;
		padding: 30rpx;
		height: auto;
		border-left: 4rpx solid #D4C9B8;
		/* 左侧装订线效果 */
		padding-left: 40rpx;
		/* 增加左侧间距 */
	}

	.content-count {
		text-align: right;
		font-size: 25rpx;
		color: #999999;
	}

	.empty {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-top: 200rpx;
	}

	.empty-img {
		width: 300rpx;
		height: 300rpx;
		opacity: 0.5;
	}

	.empty-text {
		font-size: 32rpx;
		color: #8B7D6B;
		/* 复古提示文字 */
		margin: 30rpx 0;
	}

	.empty-btn {
		background-color: #D4B483;
		/* 牛皮纸按钮色 */
		color: #5C4A36;
		/* 深棕色文字 */
		width: 60%;
		border: none;
		box-shadow: 0 2rpx 6rpx rgba(92, 74, 54, 0.1);
	}

	.empty-btn:active {
		background-color: #C7A87D;
		/* 点击态加深 */
	}
</style>